package con.fong.spring_cloud_zipkin_client.controller;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class AppController {

	private static final Logger LOG = Logger.getLogger( AppController.class.getName( ) );

	@Autowired
	private RestTemplate restTemplate;

	@Bean
	public RestTemplate getRestTemplate( ) {
		return new RestTemplate( );
	}

	@Bean
	public AlwaysSampler defaultSampler( ) {
		return new AlwaysSampler( );
	}

	@RequestMapping("/clent")
    public String clent(){
        LOG.log(Level.INFO, "calling trace clent  ");
        return restTemplate.getForObject("http://localhost:7002/clent_target", String.class);
    }
	
    @RequestMapping("/info")
    public String info(){
        LOG.log(Level.INFO, "calling trace clent ");

        return "i'm clent";

    }
}
